* Manuscript: Signaling Resolve Through Credit-Claiming
* Author: Ilayda B. Onder, The Pennsylvania State University, Department of Political Science
* Replication File for International Interactions
* April 8, 2023

* This analysis is run using STATA version 17.0
* The codes in this replication file produces Figure 2 and Figure 3
* The sections in this replication file are in order. Please run them one by one. 

* WARNING: Please set the working directory to the current Source File Location by clicking File > Change working directory

* Load the dataset
use "Analysis Data Part 2.dta", replace
* Generate dummy variable for the presence of rival groups using the number of groups variable
gen rivaldum = .
replace rivaldum = 0 if num_rivals == 0
replace rivaldum = 1 if num_rivals > 0

* Figure 2: Predicted probabilities of groups' claiming all their attacks
** Run Model 7 of Table 2
heckman stage2 c.duration c.all_log c.nonterr_casualties_log c.diversity c.shr_trans i.rel i.splinterhist i.civi, select(stage1 = i.mul_bases c.duration)
*** Calculate the predicted probabilities for Figure 2 Panel A
margins, at(duration = (5 25 45)) atmeans
*** Plot Figure 2 Panel A
set scheme plotplain
marginsplot, xtitle("Group duration (in years)") ytitle("Predicted probability") title("Duration", size(large))

** Run Model 8 of Table 2
heckman stage2 c.duration##splinterhist c.all_log c.nonterr_casualties_log c.diversity c.shr_trans i.rel, select(stage1 = i.mul_bases c.duration)
*** Calculate the predicted probabilities for Figure 2 Panel C
margins splinterhist, at(duration = (5 25 45)) atmeans
*** Split the predicted probabilities into two based on the values of the splinter group variable
parmest , bmat(r(b)) vmat(r(V)) level( `cilevel' ) fast
split parm, parse( . # )
destring parm*, replace
replace parm1 = parm1 - ( 0.05 )
*** Plot Figure 2 Panel C
set scheme plotplain
eclplot estimate min95 max95 parm1, eplot(sc) rplottype(rspike) supby(parm3, spaceby(0.1))

** Reload the dataset
use "Analysis Data Part 2.dta", replace

** Run Model 9 of Table 2
heckman stage2 c.duration##civi c.all_log c.nonterr_casualties_log c.diversity c.shr_trans i.rel, select(stage1 = i.mul_bases c.duration)
*** Calculate the predicted probabilities for Figure 2 Panel C
margins civi, at(duration = (5 25 45)) atmeans
*** Split the predicted probabilities into two based on the values of the civilian targets variable
parmest , bmat(r(b)) vmat(r(V)) level( `cilevel' ) fast
split parm, parse( . # )
destring parm*, replace
replace parm1 = parm1 - ( 0.05 )
*** Plot Figure 2 Panel C
set scheme plotplain
eclplot estimate min95 max95 parm1, eplot(sc) rplottype(rspike) supby(parm3, spaceby(0.1))

** Reload the dataset
use "Analysis Data Part 2.dta", replace

** Run Model 10 of Table 2
heckman stage2 fate_leader_dummy fate_leader_dummy_lag1 i.fate_leader_dummy_lag2 fate_leader_dummy_lag3 splinterhist civi c.all_log c.nonterr_casualties_log c.diversity c.shr_trans i.rel, select(stage1 = mul_bases fate_leader_dummy)
*** Calculate the predicted probabilities for Figure 2 Panel D
margins fate_leader_dummy_lag2, at((means) all_log nonterr_casualties_log diversity shr_trans (medians) fate_leader_dummy fate_leader_dummy_lag1 fate_leader_dummy_lag3 splinterhist civi mul_bases)
*** Plot Figure 2 Panel C
set scheme plotplain
marginsplot, xtitle("Group duration (in years)") ytitle("Predicted probability") title("Decapitation", size(large)) xlab(0 " " 1 "No Decapitation" 2 "Decapitation (L2)" 3 " ", notick)






* Figure 3: Predicted number of claimed attacks
** Run Model 15 of Table 3
zinb claimed c.duration c.all_log c.nonterr_casualties_log c.diversity c.shr_trans i.rel i.splinterhist i.civi, inflate(c.duration)
*** Calculate the predicted probabilities for Figure 3 Panel A
margins, at(duration = (5 25 45)) atmeans
* Plot Figure 3 Panel A
set scheme plotplain
marginsplot, xtitle("Group duration (in years)") ytitle("Predicted number of attacks") title("Duration", size(large))

** Run Model 16 of Table 3
zinb claimed c.duration##splinterhist c.all_log c.nonterr_casualties_log c.diversity c.shr_trans i.rel, inflate(c.duration)
*** Calculate the predicted probabilities for Figure 3 Panel C
margins splinterhist, at(duration = (5 25 45)) atmeans
*** Split the predicted probabilities into two based on the values of the splinter group variable
parmest , bmat(r(b)) vmat(r(V)) level( `cilevel' ) fast
split parm, parse( . # )
destring parm*, replace
replace parm1 = parm1 - ( 0.05 )
* Plot Figure 3 Panel C
set scheme plotplain
eclplot estimate min95 max95 parm1, eplot(sc) rplottype(rspike) supby(parm3, spaceby(0.1))

** Reload the dataset
use "Analysis Data Part 2.dta", replace

** Run Model 17 of Table 3
zinb claimed c.duration##civi c.all_log c.nonterr_casualties_log c.diversity c.shr_trans i.rel, inflate(c.duration)
*** Calculate the predicted probabilities for Figure 3 Panel B
margins civi, at(duration = (5 25 45)) atmeans
*** Split the predicted probabilities into two based on the values of the civilian targets variable
parmest , bmat(r(b)) vmat(r(V)) level( `cilevel' ) fast
split parm, parse( . # )
destring parm*, replace
replace parm1 = parm1 - ( 0.05 )
* Plot Figure 3 Panel B
set scheme plotplain
eclplot estimate min95 max95 parm1, eplot(sc) rplottype(rspike) supby(parm3, spaceby(0.1))

** Reload the dataset
use "Analysis Data Part 2.dta", replace

** Run Model 18 of Table 3
zinb claimed fate_leader_dummy fate_leader_dummy_lag1 i.fate_leader_dummy_lag2 fate_leader_dummy_lag3 splinterhist civi c.all_log c.nonterr_casualties_log c.diversity c.shr_trans i.rel, inflate(fate_leader_dummy)
*** Calculate the predicted probabilities for Figure 3 Panel D
margins fate_leader_dummy_lag2, at((means) all_log nonterr_casualties_log diversity shr_trans (medians) fate_leader_dummy fate_leader_dummy_lag1 fate_leader_dummy_lag3 splinterhist civi)
* Plot Figure 3 Panel D
set scheme plotplain
marginsplot, xtitle("Group duration (in years)") ytitle("Predicted number of attacks") title("Decapitation", size(large)) xlab(0 " " 1 "No Decapitation" 2 "Decapitation (L2)" 3 " ", notick)

